from funcs import *

if not os.path.exists('res'):
    os.mkdir('res')

关键词列表 = ['青松建化','水泥','新疆','基建']


year_months = ['202401','202402','202403','202404','202405','202406']

for year_month in year_months:
    dff = pd.read_csv(f'news_data/dff_{year_month}.csv')
    dff = dff.reset_index(drop=True)
    ddd = dff[dff['content'].str.contains('|'.join(关键词列表), regex=True, na=False)].reset_index(drop=True)
    # ddd = ddd[:100]
    ress = []
    for i in range(len(ddd)):
        if i%100==0:
            print(year_month,i)
        content = ddd.loc[i,'content']
        content = content[:15000]
        res = get_chatgpt_response(content)
        ress.append(res)
    ress = pd.DataFrame(ress)
    ress.to_csv(f'res/{year_month}.csv')